$$$ = shopCart = {
	decrease_quantity: function(rec_id) {
		var parm = {
			obj: $('#input_item_' + rec_id),
			orig: function() {
				return Number(this.obj.val());
			}
		};
		if (parm.orig() > 1) {
			parm.obj.val(parm.orig() - 1);
			parm.obj.keyup();
		}
	},
	increase_quantity: function(rec_id) {
		var parm = {
			obj: $('#input_item_' + rec_id),
			orig: function() {
				return Number(this.obj.val());
			}
		};
		parm.obj.val(parm.orig() + 1);
		parm.obj.keyup();
	},
	change_quantity: function(rec_id, store_id, spec_id, input, orig) {
		var _val = $(input).val();
		var freg = /^[0-9]\d*$/;
		if (!freg.test(_val)) {
			$(input).val('');
			return;
		}
		var pertotal = $('#pertotal_' + rec_id),
			ordertotal = $('#ordertotal_' + store_id),
			totalnum = $('#totalnum'),
			totalprice = $('#totalprice');
		$.getJSON(CART_SITE_URL + '/index.php?app=cart&act=Ajaxupdate&spec_id=' + spec_id + '&quantity=' + _val + '&jsoncallback=?', function(result) {
			if (result.done) {
				$(input).attr('changed', _val);
				pertotal.html(wl.price_format(result.data.pertotal, 2));
				ordertotal.html(wl.price_format(result.data.ordertotal, 2));
				totalnum.html(result.data.totalnum);
				totalprice.html(wl.price_format(result.data.totalprice, 2));
			} else {
				$(input).val($(input).attr('changed'));
				wl.sConfirm({
					'info': result.msg,
					'cancel': true
				});
			}
		});
	},
	'handel': {
		binding: function(o, k, j) {
			var refer = {
				bool: $(o).attr('checked'),
				res: 0,
				res2: 0,
				status: '',
				totalnum: $('#totalnum'),
				totalprice: $('#totalprice')
			};
			if (j === 2) {
				var ta = $(o).closest('.shop-total').siblings('.shop-every').find('input[type="checkbox"]'),
					shades = $('div.shop-shade');
				if (refer.bool) {
					ta.each(function() {
						$(this).attr('checked', true);
					});
					refer.status = 'able';
					shades.hide();
				} else {
					ta.each(function() {
						$(this).attr('checked', false);
					});
					refer.status = 'unable';
					shades.show();
				}
				$.post('index.php?app=cart&act=Ajaxbinding', {
					'type': 'all',
					'status': refer.status
				}, function(result) {
					if (result.done) {
						for (var i in result.data.ordertotal) { //根据店铺返回值数组更对全部店铺总价
							var val = wl.price_format(result.data.ordertotal[i], 2);
							$('#ordertotal_' + i).html(val);
						}
						refer.totalnum.html(result.data.totalnum);
						refer.totalprice.html(wl.price_format(result.data.totalprice, 2));
					} else {
						wl.sConfirm({
							'info': result.msg,
							'cancel': true
						});
					}
				}, 'json');
			} else if (k === 1) {
				var ts = $(o).closest('.shop-seller').siblings('.shop-detail').find('input[type="checkbox"]'),
					ta = $(o).closest('form').children('.shop-every').find('input[type="checkbox"]'),
					tz = $(o).closest('.shop-every').siblings('.shop-total').find('input[type="checkbox"]'),
					store_id = $(o).attr('store'),
					ordertotal = $('#ordertotal_' + store_id),
					shades = $('div[store="' + store_id + '"]');
				if (refer.bool) {
					ts.each(function() {
						$(this).attr('checked', true);
					});
					ta.each(function() {
						if ($(this).attr('checked')) {
							refer.res++;
						}
					});
					if (refer.res == ta.length) {
						tz.attr('checked', true);
					}
					refer.status = 'able';
					shades.hide();
				} else {
					tz.attr('checked', false);
					ts.each(function() {
						$(this).attr('checked', false);
					});
					refer.status = 'unable';
					shades.show();
				}
				$.post('index.php?app=cart&act=Ajaxbinding', {
					'type': 'group',
					'store_id': store_id,
					'status': refer.status
				}, function(result) {
					if (result.done) {
						ordertotal.html(wl.price_format(result.data.ordertotal, 2));
						refer.totalnum.html(result.data.totalnum);
						refer.totalprice.html(wl.price_format(result.data.totalprice, 2));
					} else {
						wl.sConfirm({
							'info': result.msg,
							'cancel': true
						});
					}
				}, 'json');
			} else {
				var ts = $(o).closest('.shop-detail').siblings('.shop-detail').find('input[type="checkbox"]'),
					tt = $(o).closest('.shop-detail').siblings('.shop-seller').find('input[type="checkbox"]'),
					ta = $(o).closest('form').children('.shop-every').find('input[type="checkbox"]'),
					tz = $(o).closest('.shop-every').siblings('.shop-total').find('input[type="checkbox"]'),
					rec_id = $(o).attr('name'),
					store_id = $(o).attr('store'),
					ordertotal = $('#ordertotal_' + store_id),
					shade = $('div[rec="' + rec_id + '"]');
				if (refer.bool) {
					ts.each(function() {
						if ($(this).attr('checked')) {
							refer.res++;
						}
					});
					if (refer.res === ts.length) {
						tt.attr('checked', true);
					}
					ta.each(function() {
						if ($(this).attr('checked')) {
							refer.res2++;
						}
					});
					if (refer.res2 == ta.length) {
						tz.attr('checked', true);
					}
					refer.status = 'able';
					shade.hide();
				} else {
					tt.attr('checked', false);
					tz.attr('checked', false);
					refer.status = 'unable';
					shade.show();
				}
				$.post('index.php?app=cart&act=Ajaxbinding', {
					'type': 'single',
					'rec_id': rec_id,
					'status': refer.status
				}, function(result) {
					if (result.done) {
						ordertotal.html(wl.price_format(result.data.ordertotal, 2));
						refer.totalnum.html(result.data.totalnum);
						refer.totalprice.html(wl.price_format(result.data.totalprice, 2));
					} else {
						wl.sConfirm({
							'info': result.msg,
							'cancel': true
						});
					}
				}, 'json');
			}
		},
		del: function(store_id, rec_id, type) {
			wl.sConfirm({
				'info': '确定删除吗？',
				'success': function() {
					var shop_every = $('#shop_every_' + store_id), //当前店铺
						shopcart = $('#shopcart-confirm'), //全部店铺
						shop_every_num = shopcart.children('div.shop-every').length, //店铺数
						no_shop = $('#no-shop'),
						ordertotal = $('#ordertotal_' + store_id),
						totalnum = $('#totalnum'),
						totalprice = $('#totalprice');
					if (type === 'single') {
						var rec_data = {
							'type': 'single',
							'contents': rec_id
						};
						var shop_detail = $('#shop_detail_' + rec_id), //行
							shop_detail_num = shop_every.find('div.shop-detail').length; //行数
					} else if (type === 'group') {
						var shop_every_inputs = shop_every.children('div.shop-each').children('div.shop-detail').find('input[type="checkbox"]'), //内容所有单选框
							shop_seller_input = shop_every.children('div.shop-each').children('div.shop-seller').find('input[type="checkbox"]'),
							allnum = shop_every_inputs.length,
							checkedinputs = {},
							select = 1,
							checkednum = 0;
						if (shop_seller_input.attr('checked')) {
							select = 1;
						} else {
							select = 0;
						}
						var rec_data = {
							'type': 'group',
							'store_id': store_id,
							'select': select,
							'contents': {}
						};
						shop_every_inputs.each(function(index) {
							if ($(this).attr('checked')) {
								rec_data.contents[index] = $(this).attr('name');
								checkedinputs[index] = $('#shop_detail_' + $(this).attr('name'));
								checkednum++;
							}
						});
					} else if (type === 'all') {
						var rec_data = {
							'type': 'all',
							'contents': {}
						};
						var allinputs = $('#shopcart-confirm').find('input[type="checkbox"]'), //单选框
							allnum = allinputs.length,
							checkednum = 0;
						allinputs.each(function(index) {
							if ($(this).attr('checked')) {
								checkednum++;
							}
						});
					}
					var str = JSON.stringify(rec_data);
					$.post('index.php?app=cart&act=Ajaxdel', {
						'rec_data': str
					}, function(result) {
						if (result.done) {
							if (type === 'single') {
								try {
									if (shop_detail_num > 1) {
										shop_detail.remove();
										ordertotal.html(wl.price_format(result.data.ordertotal, 2));
										totalnum.html(result.data.totalnum);
										totalprice.html(wl.price_format(result.data.totalprice, 2));
									} else if (shop_detail_num <= 1 && shop_every_num > 1) {
										shop_every.remove();
										totalnum.html(result.data.totalnum);
										totalprice.html(wl.price_format(result.data.totalprice, 2));
									} else if (shop_detail_num <= 1 && shop_every_num <= 1) {
										shopcart.remove();
										no_shop.removeClass('f-dn');
									}
								} catch (e) {
									window.alert('通信异常，请重新尝试或联系客服');
								}
							} else if (type === 'group') {
								try {
									if (checkednum == 0) {
										wl.sConfirm({
											'info': '请选择删除项',
											'cancel': true
										});
									} else if (checkednum < allnum) {
										for (var i in checkedinputs) {
											checkedinputs[i].remove();
										}
										shop_seller_input.attr('checked', false);
										ordertotal.html(wl.price_format(result.data.ordertotal, 2));
										totalnum.html(result.data.totalnum);
										totalprice.html(wl.price_format(result.data.totalprice, 2));
									} else if (checkednum == allnum && shop_every_num > 1) {
										shop_every.remove();
										totalnum.html(result.data.totalnum);
										totalprice.html(wl.price_format(result.data.totalprice, 2));
									} else if (checkednum == allnum && shop_every_num <= 1) {
										shopcart.remove();
										no_shop.removeClass('f-dn');
									}
								} catch (e) {
									window.alert('通信异常，请重新尝试或联系客服');
								}
							} else if (type === 'all') {
								if (checkednum == allnum) {
									shopcart.remove();
									no_shop.removeClass('f-dn');
								} else {
									wl.sConfirm({
										'info': '请全选后再操作',
										'cancel': true
									});
								}
							}
						} else {
							wl.sConfirm({
								'info': result.msg,
								'cancel': true
							});
						}
					}, 'json');
				}
			});
		},
		favorite: function(type, goods_id) {
			var input = $('#shoptotal'),
				info = '';
			if (type === 'single') {
				//info = '收藏成功';
				$.getJSON(USER_SITE_URL + '/index.php?app=my_favorite&act=add&type=goods&item_id=' + goods_id + '&jsoncallback=?', function(result) {
					if (result.done) {
						wl.sConfirm({
							'info': result.msg,
							'cancel': true
						});
					} else {
						wl.sConfirm({
							'info': result.msg,
							'cancel': true
						});
					}
				});
			} else if (type === 'all') {
				info = '全部收藏成功';
				if (input.attr('checked')) {
					$.getJSON(CART_SITE_URL + '/index.php?app=cart&act=Ajaxfavorite&type=' + type + '&jsoncallback=?', function(result) {
						if (result.done) {
							wl.sConfirm({
								'info': info,
								'cancel': true
							});
						} else {
							wl.sConfirm({
								'info': result.msg,
								'cancel': true
							});
						}
					});
				} else {
					wl.sConfirm({
						'info': '请全选后再操作',
						'cancel': true
					});
				}
			}
		}

	},
	'constant': {
		CHANGED: 0 //购物车 input-changed
	}

};